﻿namespace hedefgrup.graphicsLibrary
{
    using System;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.IO;

    public abstract class graphic
    {
        public Font mapNameFont = new Font("tahoma", 10f, FontStyle.Bold);
        public string[] mapNameLines;
        public Font xAxisFont = new Font("tahoma", 8f);
        public int xInterval;
        public Font xLabelFont = new Font("tahoma", 6.5f);
        public string[] xLabels;
        public int xMaximumValue;
        public int xMinimumValue;
        public float[] xValues;
        public Font yAxisFont = new Font("tahoma", 8f);
        public int yInterval;
        public Font yLabelFont = new Font("tahoma", 6.5f);
        public string[] yLabels;
        public int yMaximumValue;
        public int yMinimumValue;
        public float[] yValues;

        protected graphic()
        {
        }

        public abstract Bitmap generateImage();
        public void WriteImage(Stream outputStream)
        {
            this.WriteImage(outputStream, ImageFormat.Gif);
        }

        public void WriteImage(string fileName)
        {
            this.WriteImage(fileName, ImageFormat.Gif);
        }

        public void WriteImage(Stream outputStream, ImageFormat imageFormat)
        {
            using (Bitmap bitmap = this.generateImage())
            {
                bitmap.Save(outputStream, imageFormat);
                bitmap.Dispose();
            }
        }

        public void WriteImage(string fileName, ImageFormat imageFormat)
        {
            FileStream outputStream = File.Create(fileName);
            this.WriteImage(outputStream, imageFormat);
            outputStream.Flush();
            outputStream.Close();
            outputStream.Dispose();
        }
    }
}

